import request from '@u/request'
const UserModule = 'index'

// 获取指标
export function queryQuotaList(queryInfo) {
  return request.post(
    `${UserModule}/quota/queryQuotaInfo`,
    JSON.stringify(queryInfo)
  )
}

// 根据id获取单个指标体系信息
export function getQuotaByPkid(pkid) {
  return request.get(`${UserModule}/quota/getQuotaInfoByPkid`, {
    params: {
      pkid,
    },
  })
}

// 多条件查询
export function queryMulConditions(query) {
  return request.get(`${UserModule}/index/query`, {
    params: {
      ...query,
    },
  })
}

// 更新指标体系
export function updateQuota(quotaInfo) {
  return request.put(
    `${UserModule}/quota/updateQuotaInfo`,
    JSON.stringify(quotaInfo)
  )
}

// 新增指标体系
export function insertQuota(quotaInfo) {
  return request.post(
    `${UserModule}/quota/insertQuotaInfo`,
    JSON.stringify(quotaInfo)
  )
}

// 删除指标体系
export function deleteQuota(pkid) {
  return request.delete(`${UserModule}/quota/deleteQuotaInfoByPkid`, {
    params: {
      pkid,
    },
  })
}

// 获取有数据的地区列表
export function getAreaList(year = null) {
  return request.get(`${UserModule}/quota/area/query`, {
    params: { year },
  })
}

// 获取所有的地区列表
export function getAllAreaList() {
  return request.get(`${UserModule}/area/getAreaList`)
}

// 获取维度
export function queryDimension(query) {
  return request.get(`${UserModule}/index/dimension/query`, {
    params: {
      ...query,
    },
  })
}

// 根据指标获取维度
export function queryDimensionByIndex(query) {
  return request.get(`${UserModule}/index/dimension/query.json`, {
    params: {
      ...query,
    },
  })
}

// 获取维度详情
export function getDimensionDetail(pkid) {
  return request.get(`${UserModule}/index/dimension/query/id`, {
    params: {
      pkid,
    },
  })
}

// 获取维度图标
export function getIconList(isDefault) {
  return request.get(`${UserModule}/index/dimension/icons`, {
    params: {
      isDefault,
    },
  })
}

// 新增维度
export function insertDimension(dimensionInfo) {
  return request.post(
    `${UserModule}/index/dimension/insert`,
    JSON.stringify(dimensionInfo)
  )
}

// 新增指标
export function insertIndicator(indicatorInfo) {
  return request.post(
    `${UserModule}/index/data/add`,
    JSON.stringify(indicatorInfo)
  )
}

// 修改指标
export function updateIndicator(indicatorInfo) {
  return request.put(
    `${UserModule}/index/data/update/${indicatorInfo.id}`,
    JSON.stringify(indicatorInfo)
  )
}

// 查询指定指标的相关信息（包括了所属维度、指标体系、包含了关联的指标）
export function queryIndicator(pkid) {
  return request.get(`${UserModule}/index/data/query`, {
    params: {
      pkid,
    },
  })
}

// 删除指定指标关联的指标信息
export function deleteRelatIndicator(dataId) {
  return request.delete(`${UserModule}/group/delete`, {
    params: {
      dataId,
    },
  })
}

// 删除指定指标关联的服务信息
export function deleteIndicator(pkid) {
  return request.delete(`${UserModule}/index/data/delete`, {
    params: {
      pkid,
    },
  })
}

// 更新指定指标关联的服务信息
export function updateIndicatorInfo(grorpId, dataIds) {
  return request.put(
    `${UserModule}/group/update/${grorpId}`,
    JSON.stringify(dataIds)
  )
}

// 根据体系id查询维度
export function getDimensionByQuotaId(quotaId) {
  return request.get(`${UserModule}/index/dimension/selectDsByQuotaId`, {
    params: {
      quotaId,
    },
  })
}

// 根据维度 id 查询指定维度下的指标(不带视角)
// export function getIndicatorByDimensionId(dimensionId, isRelease = null) {
//   return request.get(`${UserModule}/index/data/query/getByDimensionId`, {
//     params: {
//       dimensionId,
//       isRelease,
//     },
//   });
// }

// 根据维度 id 查询指定维度下的指标(带视角)
export function getIndicatorByDimensionId(dimensionId, isRelease = null) {
  return request.get(`${UserModule}/index/data/query/view/getByDimensionId`, {
    params: {
      dimensionId,
      isRelease,
    },
  })
}
// 带视角
export function getViewIndicatorByDimensionId(dimensionId, isRelease = null) {
  return request.get(`${UserModule}/index/data/query/view/getByDimensionId`, {
    params: {
      dimensionId,
      isRelease,
    },
  })
}

// 校验年份地区是否存在数据
export function judgeQuoInfo(year, areaId) {
  return request.get(`${UserModule}/quota/judgeQuoInfo`, {
    params: {
      year,
      areaId,
    },
  })
}

// 获取存在数据的年份列表
export function getYearList(areaId = null) {
  return request.get(`${UserModule}/quota/getYearList`, {
    params: { areaId },
  })
}

// 查询指标下关联的服务信息
export function getServiceByIndicatorId(dataId) {
  return request.get(`${UserModule}/index/data/service/query`, {
    params: {
      dataId,
    },
  })
}

// 添加指标关联的服务信息
export function addService(dataId, serviceList) {
  return request.post(
    `${UserModule}/index/data/service/add/${dataId}`,
    JSON.stringify(serviceList)
  )
}

// 删除指定指标关联的服务信息
export function deleteServiceByIndicatorId(pkid) {
  return request.delete(`${UserModule}/index/data/service/delete`, {
    params: {
      pkid,
    },
  })
}

// 修改指定指标关联的指定服务信息
export function updateService(dataId, serviceInfo) {
  return request.put(
    `${UserModule}/index/data/service/update/${dataId}`,
    JSON.stringify(serviceInfo)
  )
}

// 将维度下已填写的指标发布

export function releaseIndex(pkid) {
  return request.put(`${UserModule}/index/quota/release/${pkid}`)
}

// 新增分析视角

export function addView(params) {
  return request.post(`${UserModule}/view/add`, JSON.stringify(params))
}

// 更新分析视角
export function updateView(pkid, params) {
  return request.put(
    `${UserModule}/view/update/${pkid}`,
    JSON.stringify(params)
  )
}
// 更新分析视角排序
export function updateViewIndex(viewId, previousViewId) {
  return request.put(
    `${UserModule}/view/update/order?viewId=${viewId}&previousViewId=${previousViewId}`
  )
}

// 删除分析视角
export function delView(pkid) {
  return request.delete(`${UserModule}/view/delete`, {
    params: {
      pkid,
    },
  })
}
export const uploadUrl = `${window.BASE_URL}/${UserModule}/index/uploadIcon`
export const quatoUploadUrl = `${window.BASE_URL}/${UserModule}/index/upload`
